package com.xbongbong.crm.perform.query.render.insert;

import com.xbongbong.crm.abstracts.AbstractCrmNewPageRenderService;
import com.xbongbong.paas.domain.entity.ext.PaasFormEntityExt;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.field.SaasParticularAttributePoJo;
import com.xbongbong.paas.pojo.dto.FormDataAddGetDTO;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.DateTimeUtil;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.CommunicatePlanEnum;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * @author sunshaoxiang
 * @ClassName CommunicatePlanNewPageRenderServiceImpl
 * @Description 访客计划 add get 业务层
 * @Date 2022/5/26 9:51
 * @Version 1.0
 **/
@Service("communicatePlanNewPageRenderServiceImpl")
public class CommunicatePlanNewPageRenderServiceImpl extends AbstractCrmNewPageRenderService {


    @Override
    public List<Integer> businessType() {
        return Collections.singletonList(XbbRefTypeEnum.COMMUNICATE_PLAN.getCode());
    }

    @Override
    public void businessHandleExplain(FormDataAddGetDTO formDataAddGetDTO, List<FieldAttrEntity> explainList, PaasFormEntityExt form) throws XbbException {

        for (FieldAttrEntity fieldAttrEntity : explainList) {
            String attr = fieldAttrEntity.getAttr();
            if (Objects.equals(attr, CommunicatePlanEnum.NOTIFY_TIME.getAttr())) {
                SaasParticularAttributePoJo saasParticularAttributePoJo = fieldAttrEntity.getSaasParticularAttributePoJo();
                saasParticularAttributePoJo = saasParticularAttributePoJo == null ? new SaasParticularAttributePoJo() : saasParticularAttributePoJo;
                saasParticularAttributePoJo.setDateLimit(DateTimeUtil.getTodayInt());
                saasParticularAttributePoJo.setLimitType(false);
                fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
            }
        }
    }
}
